package com.eling.elcms.cater.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.Attendant;
import com.eling.elcms.travel.model.RoomPersonalInfo;
import com.eling.elcms.travel.model.WelfareConsumptionCoupon.Status;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 顾客帐户
 * 
 * @author zhoulin
 *
 */
@Indexed
@Entity
@Table(name = "cate_travelaccount")
@CriteriaEnhancers(criteriaEnhancers = {@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class)})
public class TravelAccount extends BaseModel {

	private static final long serialVersionUID = 4797863665179816671L;

	@Id
	@In
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	private Long pkTravelAccount;

	/** 顾客 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkRoomPersonalInfo")
	@IndexedEmbedded(depth = 1)
	private RoomPersonalInfo roomPersonalInfo;
	
	/** 员工*/
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkAttendance")
	@IndexedEmbedded(depth = 1)
	private Attendant attendant;

	/** 余额 */
	@Column
	@Field
	private Double balance;
	
	/** 人员类型*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private AccountType accountType;
	
	/** 帐户状态*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private Status status;

	/** 创建（发卡）日期 */
	@Column
	@Between
	private Date creatDate;

	@Version
	private Integer version;
	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum AccountType {
		Attendant("员工"),
		Consumer("客户");

		private String display;

		AccountType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkTravelAccount() {
		return pkTravelAccount;
	}

	public void setPkTravelAccount(Long pkTravelAccount) {
		this.pkTravelAccount = pkTravelAccount;
	}

	public Attendant getAttendant() {
		return attendant;
	}

	public void setAttendant(Attendant attendant) {
		this.attendant = attendant;
	}

	public RoomPersonalInfo getRoomPersonalInfo() {
		return roomPersonalInfo;
	}

	public void setRoomPersonalInfo(RoomPersonalInfo roomPersonalInfo) {
		this.roomPersonalInfo = roomPersonalInfo;
	}

	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public Date getCreatDate() {
		return creatDate;
	}

	public void setCreatDate(Date creatDate) {
		this.creatDate = creatDate;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public AccountType getAccountType() {
		return accountType;
	}

	public void setAccountType(AccountType accountType) {
		this.accountType = accountType;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

}
